home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* blend_equations.c
- *
- * Demonstrates the use of the blend_minmax,
- * blend_subtract, and blend_logic_op extensions using
- * glBlendEquationEXT.
- *
- * Over a two-color backround, draw rectangles using twelve new
- * blend options. The values are read back as UNSIGNED_BYTE
- * and printed in hex over each value. These values are useful
- * for logic op comparisons when channels are 8 bits deep.
- *
- * Escape key - exit program
- */
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- void printHelp( char * );
-
- static void printColorStrings( GLvoid );
- static void renderBitmapString( void *, char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static int deltaY;
- static GLint windW = 800, windH = 840;
- static GLvoid *font;
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width/4, height/8);
- glutInitWindowSize( windW, windH );
- glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
-
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - demonstrates the use of the blend_minmax,\n"
- "blend_subtract, and blend_logic_op extensions\n\n"
- "Escape key - exit the program\n\n",
- progname);
- }
-
- void
- initgfx( void )
- {
- const GLubyte *s;
- char *extName1 = "GL_EXT_blend_subtract";
- char *extName2 = "GL_EXT_blend_minmax";
- char *extName3 = "GL_EXT_blend_logic_op";
-
- font = GLUT_BITMAP_TIMES_ROMAN_24;
-
- glShadeModel(GL_FLAT);
- glClearColor(0.5, 0.6, 0.1, 1.0);
-
- /* Make sure new blend_* extensions exist */
- if (glutExtensionSupported(extName1) == 0) {
- printf("%s is not supported by the server.\n", extName1);
- }
- if (glutExtensionSupported(extName2) == 0) {
- printf("%s is not supported by the server.\n", extName2);
- }
- if (glutExtensionSupported(extName3) == 0) {
- printf("%s is not supported by the server.\n", extName3);
- }
- }
-
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape(int width, int height)
- {
- windW = (GLint)width;
- windH = (GLint)height;
-
- glViewport(0, 0, (GLint)width, (GLint)height);
- deltaY = windH/14;
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0, windW, 0, windH);
- glMatrixMode(GL_MODELVIEW);
- }
-
- static void
- renderBitmapString( void *font, char *string )
- {
- int i;
- int len = (int) strlen(string);
- for (i = 0; i < len; i++) {
- glutBitmapCharacter(font, string[i]);
- }
- }
-
- static void
- printColorStrings( GLvoid )
- {
- GLubyte ubbuf[3];
- int i, xleft, xright;
- char colorString[20];
-
- xleft = 5 + windW/4;
- xright = 5 + windW/2;
-
- glColor3f(0.8, 0.8, 0.8);
- for (i = windH - deltaY + 4; i > 0; i-=deltaY) {
- glReadPixels(xleft, i+10, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
- ubbuf);
- sprintf(colorString, "(0x%x, 0x%x, 0x%x)",
- ubbuf[0], ubbuf[1], ubbuf[2]);
- glRasterPos2f(xleft, i);
- renderBitmapString(font,colorString);
-
- glReadPixels(xright, i+10, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
- ubbuf);
- sprintf(colorString, "(0x%x, 0x%x, 0x%x)",
- ubbuf[0], ubbuf[1], ubbuf[2]);
- glRasterPos2f(xright, i);
- renderBitmapString(font,colorString);
- }
- }
-
- void
- drawScene(void)
- {
- GLubyte ubbuf[3];
- int stringOffset = 5, stringx = 8;
- int i, x1, x2;
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- /* Draw background */
- glColor3f(0.1, 0.1, 1.0);
- glRectf(0.0, 0.0, windW/2, windH);
-
- /* Draw labels */
- glColor3f(0.8, 0.8, 0.0);
- i = windH - deltaY + stringOffset;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"DEST");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"SOURCE");
-
- #ifdef GL_EXT_blend_subtract
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"subtract");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"reverse_subtract");
- #endif
-
- #ifdef GL_EXT_blend_minmax
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"min");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"max");
- #endif
-
- #ifdef GL_EXT_blend_logic_op
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"clear");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"set");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"copy");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"noop");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"and");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"invert");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"or");
-
- i -= deltaY;
- glRasterPos2f(stringx, i);
- renderBitmapString(font,"xor");
- #endif
-
- /* Leave one rectangle of background color */
- i = windH - deltaY;
- x1 = windW/4;
- x2 = 3 * windW/4;
-
- /* Draw foreground color for comparison */
- i -= deltaY;
- glColor3f(0.9, 0.2, 0.8);
- glRectf(x1, i, x2, i+deltaY);
-
- /* Begin test cases */
- glEnable(GL_BLEND);
-
- #ifdef GL_EXT_blend_subtract
- /* set blending factors */
- glBlendFunc(GL_ONE, GL_ONE);
-
- i -= deltaY;
- glBlendEquationEXT(GL_FUNC_SUBTRACT_EXT);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT);
- glRectf(x1, i, x2, i+deltaY);
-
- /* return to default blending factors */
- glBlendFunc(GL_ONE, GL_ZERO);
- #endif
-
- #ifdef GL_EXT_blend_minmax
- i -= deltaY;
- glBlendEquationEXT(GL_MIN_EXT);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glBlendEquationEXT(GL_MAX_EXT);
- glRectf(x1, i, x2, i+deltaY);
- #endif
-
- #ifdef GL_EXT_blend_logic_op
- glBlendEquationEXT(GL_LOGIC_OP);
-
- i -= deltaY;
- glLogicOp(GL_CLEAR);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_SET);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_COPY);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_NOOP);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_AND);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_INVERT);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_OR);
- glRectf(x1, i, x2, i+deltaY);
-
- i -= deltaY;
- glLogicOp(GL_XOR);
- glRectf(x1, i, x2, i+deltaY);
- glRectf(x1, i+deltaY/2, x2, i+deltaY/2+5);
- #endif
- glDisable(GL_BLEND);
-
- printColorStrings();
- glFlush();
- }
-
-